package com.yxb.square.service.impl;

import java.util.Collections;
import java.util.List;

import com.yxb.common.core.page.TableDataInfo;
import com.yxb.common.utils.DateUtils;
import com.yxb.orders.domain.MyOrders;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.yxb.square.mapper.TutoringSquareMapper;
import com.yxb.square.domain.TutoringSquare;
import com.yxb.square.service.ITutoringSquareService;

/**
 * 家教广场Service业务层处理
 * 
 * @author 林德炫
 * @date 2025-03-28
 */
@Service
public class TutoringSquareServiceImpl implements ITutoringSquareService 
{
    @Autowired
    private TutoringSquareMapper tutoringSquareMapper;

    /**
     * 查询家教广场
     * 
     * @param requestId 家教广场主键
     * @return 家教广场
     */
    @Override
    public TutoringSquare selectTutoringSquareByRequestId(Long requestId)
    {
        return tutoringSquareMapper.selectTutoringSquareByRequestId(requestId);
    }

    /**
     * 查询家教广场列表
     * 
     * @param tutoringSquare 家教广场
     * @return 家教广场
     */
    @Override
    public List<TutoringSquare> selectTutoringSquareList(TutoringSquare tutoringSquare)
    {
        return tutoringSquareMapper.selectTutoringSquareList(tutoringSquare);
    }

    //    查找教员接单
    @Override
    public List<TutoringSquare> selectListByStatus(TutoringSquare tutoringSquare) {
        return tutoringSquareMapper.selectListByStatus(tutoringSquare);
    }

    /**
     * 新增家教广场
     * 
     * @param tutoringSquare 家教广场
     * @return 结果
     */
    @Override
    public int insertTutoringSquare(TutoringSquare tutoringSquare)
    {
        tutoringSquare.setAcceptedTime(null);
        tutoringSquare.setCreateTime(DateUtils.getNowDate());

//        if (tutoringSquare.getStatus().equals("approved")){
//            MyOrders myOrders = new MyOrders();
//            myOrders.setParentName(tutoringSquare.getName());
//            myOrders.setParentPhoneNumber(tutoringSquare.getPhoneNumber());
//            myOrders.setTeacherName(tutoringSquare.getTeacherName());
//            myOrders.setOrderDetail(tutoringSquare.getContent());
//            myOrders.setAcceptedTime(tutoringSquare.getAcceptedTime());
//            myOrders.setOrderStatus("approved");
//        }
        return tutoringSquareMapper.insertTutoringSquare(tutoringSquare);
    }


    /**
     * 修改家教广场
     * 
     * @param tutoringSquare 家教广场
     * @return 结果
     */
    @Override
    public int updateTutoringSquare(TutoringSquare tutoringSquare)
    {
        tutoringSquare.setAcceptedTime(DateUtils.getNowDate());
        return tutoringSquareMapper.updateTutoringSquare(tutoringSquare);
    }

    /**
     * 批量删除家教广场
     * 
     * @param requestIds 需要删除的家教广场主键
     * @return 结果
     */
    @Override
    public int deleteTutoringSquareByRequestIds(Long[] requestIds)
    {
        return tutoringSquareMapper.deleteTutoringSquareByRequestIds(requestIds);
    }

    /**
     * 删除家教广场信息
     * 
     * @param requestId 家教广场主键
     * @return 结果
     */
    @Override
    public int deleteTutoringSquareByRequestId(Long requestId)
    {
        return tutoringSquareMapper.deleteTutoringSquareByRequestId(requestId);
    }

    @Override
    public List<TutoringSquare> listSquareByUserName(String userName) {
        return tutoringSquareMapper.listSquareByUserName(userName);
    }


    //获取教员接单（我的接单）
    @Override
    public List<TutoringSquare> listSquareByTeacher(String teacherName,  String name) {
        return tutoringSquareMapper.listSquareByTeacher(teacherName, name);
    }

    //获取家长发布（我的发布）
    @Override
    public List<TutoringSquare> listSquareByParent(String parentName, String status) {
        return tutoringSquareMapper.listSquareByParent(parentName, status);
    }

}
